﻿/*global analogue, window*//*jslint bitwise: true, browser: true, eqeqeq: true, immed: true, newcap: true, nomen: true, onevar: true, plusplus: true, regexp: true, undef: true, white: true, indent: 4*/

analogue.detect = (function (window) {
    var a, div = document.createElement('div'), root = document.documentElement;
    root.className = 'hasJs';
    div.innerHTML = '<a href="/a" style="color:red;float:left;opacity:.5">a</a><input />';
    div.getElementsByTagName('input')[0].setAttribute('name', 'nameAttribute');
    a = div.getElementsByTagName('a')[0];
    if (!window.HTMLElement) {
        if (window.Element && window.Element.prototype) {
            window.HTMLElement = window.Element;
        } else {
            if (window['[[DOMElement.prototype]]']) {
                window.HTMLElement = function () {};
                window.HTMLElement.prototype = window['[[DOMElement.prototype]]'];
            }
        }
    }
    return {
        cssFloat: !!a.style.cssFloat ? 'cssFloat' : 'styleFloat',
        getElementById: (function () {
            var div = document.createElement('div'), id = 'id' + new Date().getTime(), value = true;
            div.innerHTML = '<a name="' + id + '"></a>';
            root.insertBefore(div, root.firstChild);
            value = !div.ownerDocument.getElementById(id);
            root.removeChild(div);
            return value;
        }()),
        href: a.getAttribute('href') === '/a',
        style: (/red/).test(a.getAttribute('style')),
        setAttribute: (/nameAttribute/).test(div.innerHTML),
        arraySlice: (function () {
            try {
                return !!Array.prototype.slice.call(root.childNodes)[0];
            } catch (e) {
                return false;
            }
        }()),
        opacity: a.style.opacity === '0.5',
        textContent: a.textContent === 'a' ? 'textContent' : 'innerText'
    };
}(this));